<html>
<head>
	<meta charset='utf-8' />
	<title>商户注册</title>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
	<style>
		@media screen and (max-width:450px){
			#Content,#Nav_bottom,#Back_Btn{width:98%;margin:0 auto}

			/*页面宽度900以下时 .abc的宽度为450*/
		}
		@media screen and (min-width:450px){
			#Content,#Nav_bottom,#Back_Btn{width:450px;margin:0 auto}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
	</style>
</head>
<body style='padding:0;margin:0'>



	<!-- 1 Content容器 -->
	<div id='Content' style=''>


		<img src="../Public/Image/base.png" alt="暂无图片" id='Banner' onerror='this.src="../Public/Image/base.png"' style='width:100%;' />

		<!--编辑或添加商户信息-->
		<div id='Store_Main_SubArea'>
			<h2 style='text-align:center;color:blue'>商户注册</h2>

			<div style='margin:10px auto;display:flex' id='Register_AreaSelect'>
				<div style='width:100px;text-align:right'>所在区域：</div>
				<div style='flex:1' id='county_name'></div>
			</div>

			<div style='margin:10px auto;display:flex'>
				<div style='width:100px;text-align:right'>登陆账号：</div>
				<div style='flex:1'><input placeholder='必填' id='Register_Account' style='width:90%' /></div>
			</div>

			<div style='margin:10px auto;display:flex'>
				<div style='width:100px;text-align:right'>登陆密码：</div>
				<div style='flex:1'><input placeholder='必填' type='password' id='Register_Pwd1' style='width:90%' /></div>
			</div>
			<div style='margin:10px auto;display:flex'>
				<div style='width:100px;text-align:right'>确认密码：</div>
				<div style='flex:1'><input placeholder='必填' type='password' id='Register_Pwd2' style='width:90%' /></div>
			</div>
			<div style='margin:10px auto;display:flex'>
				<div style='width:100px;text-align:right'>密保问题：</div>
				<div style='flex:1'><input placeholder='必填' type='text' id='Register_Question' style='width:90%' /></div>
			</div>
			<div style='margin:10px auto;display:flex'>
				<div style='width:100px;text-align:right'>密保答案：</div>
				<div style='flex:1'><input placeholder='必填' type='text' id='Register_Answer' style='width:90%' /></div>
			</div>


			<div style='margin:10px auto;display:flex'>
				<div style='width:100px;text-align:right'>商户名称：</div>
				<div style='flex:1'><input placeholder='必填' id='Register_Name' style='width:90%' /></div>
			</div>
			<div style='margin:10px auto;display:flex'>
				<div style='width:100px;;text-align:right'>联系电话：</div>
				<div style='flex:1'><input placeholder='必填' id='Register_Phone' /></div>
			</div>
			<div style='margin:10px auto;display:flex'>
				<div style='width:100px;text-align:right'>Q Q：</div>
				<div style='flex:1'><input id='Register_Qq' /></div>
			</div>
			<div style='margin:10px auto;display:flex'>
				<div style='width:100px;;text-align:right'>微信：</div>
				<div style='flex:1'><input id='Register_Wx' /></div>
			</div>
			<div style='margin:10px auto;display:flex'>
				<div style='width:100px;;text-align:right'>商户地址：</div>
				<div style='flex:1'><input id='Register_Addr' style='width:90%' /></div>
			</div>
			<div style='margin:10px auto;display:flex'>
				<div style='width:100px;;text-align:right'>商户描述：</div>
				<div style='flex:1'><textarea id="Register_Info" style='width:90%;height:150px;resize:none' ></textarea></div>
			</div>


			<div style='margin:10px auto;display:flex'>
				<div style='width:100px;text-align:right'>店铺封面：</div>
				<div style='width:150px'>
					<input type="file" id='Register_File'  />
				</div>
			</div>


			<div style='text-align:center;margin:20px auto'>
				<button id='Register_SubBtn'>注册</button>
				<button onclick='history.go(-1)'>返回</button>
			</div>
		</div>

		<div id='Notice'></div>
	</div><!-- 1 Content容器结束 -->




</body>
</html>

<script src='../Public/jquery.js'></script>
<script src='../Public/fun.js'></script>
<script src='../Public/store.js'></script>

<script>
	var cityInfo = _store_getCurrentCityInfo();	//检测并获取当前缓存的城市信息
	var requestAddr = _store_getServerAddr();	//获取缓存的后台请求地址
	var BannerTmp = '';		//缓存封面图片文件

	$(function(){
		$('#county_name').text(cityInfo[3]);	//显示当前城市名


		//选择图片并显示，及保存到临时变量中
		SelectOrViewImg('Register_File','Banner',function(file){
			if(file != 'err'){
				BannerTmp = file;
			}else{
				A('文件选择出现异常!');exit
			}
		});

		
	});






	//添加或编辑商户信息提交
	$('#Register_SubBtn').click(function(){
		var Register_Account = ChangeChar($('#Register_Account').val().trim());
		Field_Check(/^[a-zA-Z]\w{3,20}$/,Register_Account,'js账号非法!');

		var Register_Pwd1 = ChangeChar($('#Register_Pwd1').val().trim());
		Field_Check(/^.{6,20}$/,Register_Pwd1,'js密码长度在6-20之间!');
		var Register_Pwd2 = ChangeChar($('#Register_Pwd2').val().trim());
		if(Register_Pwd1 != Register_Pwd2){
			A('两次密码不一致！');return;
		}


		var Register_Question = ChangeChar($('#Register_Question').val().trim());
		Field_Check(/^.{3,20}$/,Register_Name,'js密保问题长度为3-20个字符!');

		var Register_Answer = ChangeChar($('#Register_Answer').val().trim());
		Field_Check(/^.{3,20}$/,Register_Name,'js密保答案长度为3-20个字符!');

		var Register_Name = ChangeChar($('#Register_Name').val().trim());
		Field_Check(/^.{3,20}$/,Register_Name,'js商户名长度为3-20个字符!');

		var Register_Phone = ChangeChar($('#Register_Phone').val().trim());
		Field_Check(/^[1-9][0-9]{6,11}$/,Register_Phone,'js电话格式不正确!');
	
		var Register_Qq = ChangeChar($('#Register_Qq').val().trim());
		Field_Check(/^[1-9][0-9]{4,14}$|^$/,Register_Qq,'jsQQ号不正确!');

		var Register_Wx = ChangeChar($('#Register_Wx').val().trim());
		Field_Check(/^[a-zA-z0-9_-]{3,30}$|^$/,Register_Wx,'js微信号格式不正确!');

		var Register_Addr = ChangeChar($('#Register_Addr').val().trim());
		Field_Check(/^.{0,50}$|^$/,Register_Addr,'js地址长度不超过50个字符!');

		var Register_Info = ChangeChar($('#Register_Info').val().trim());
		Field_Check(/^.{0,300}$/,Register_Info,'js商户描述不得为空且不得超过300字符!');
	





		//Notice('请求处理中......');

		var formData = new FormData();
		formData.append('db_host',cityInfo[1]);

		formData.append('cityCode',cityInfo[0]);
		formData.append('account',Register_Account);
		formData.append('pwd',Register_Pwd1);
		formData.append('name',Register_Name);
		formData.append('phone',Register_Phone); 
		formData.append('answer',Register_Answer); 
		formData.append('question',Register_Question); 

		
		if(Register_Qq){
			formData.append('qq',Register_Qq); 
		}
		if(Register_Wx){
			formData.append('wx',Register_Wx); 
		}
		if(Register_Addr){
			formData.append('addr',Register_Addr); 
		}
		if(Register_Info){
			formData.append('info',Register_Info); 
		}
		if(BannerTmp){
			formData.append('banner',BannerTmp); //添加文件
		}


		formData.append('type','storeRegister'); 
		
		Notice('处理中...');
		AjaxFile(formData,function(res){
			Notice();
			if(res == 'ok'){
				A('商户创建成功！');
				history.go(-1);
			}else if(res == 'err2'){
				A('账号已存在！');
			}else if(res == 'err4'){
				A('图片大小超限！');
			}else{
				A('操作异常！');
			}
		},requestAddr)


		// Ajax_FormData(formData,requestAddr,function(res){
		// 	C(res);return;
		// 	$('#Register_CodeImg').trigger('click');	//变换验证码
		// 	if(res && (/^{"id".*}$/.test(res) || /^{.*}$/.test(res))){
		// 		A('注册成功，等待审核！');
		// 		sessionStorage.StoreInfo = res;
		// 		location.replace('index.html');
		// 	}else{
		// 		switch(res){
		// 			case 'err1':
		// 				A('验证码不正确!');
		// 			break;
		// 			case 'err7':
		// 				A('数据没有任何改动!');
		// 			break;
		// 			default:
		// 				A('注册系统异常，请稍再试!');
		// 			break;
		// 		}
		// 	}
		// },0,1);

	});

</script>